<?php

class User extends ExtendedController {

    function __construct() {
        parent::__construct();
    }

    function index() {
        //show all users
    }

    function create($id) {
        //neuen user anlegen
        //wie edit nur ohne vorherige prüfung

        echo $id;

//        $this->viewValues = array(
//            'header' => array(),
//            'body' => array(),
//            'footer' => array()
//        );
//
//        $this->load->view('viewUserCreate', $this->viewValues['body']);
    }

    function edit($id = null) {
        $userObject = new MUser($id);
        if ($userObject->exists()) {
            if (true) { //!empty($this->input->post('submit'))

                $userObject->name = $this->input->post('name');
                $userObject->password = $this->input->post('password');

                $validationRules = array(
                    array(
                        'field' => 'name',
                        'label' => 'Name',
                        'rules' => 'trim|required|min_length[3]|max_length[32]'
                    ),
                    array(
                        'field' => 'password',
                        'label' => 'Password',
                        'rules' => 'trim|required|min_length[8]'
                    ),
                    array(
                        'field' => 'passconf',
                        'label' => 'Password Confirmation',
                        'rules' => 'trim|required|matches[password]|min_length[8]'
                    ),
                    array(
                        'field' => 'email',
                        'label' => 'Email',
                        'rules' => 'trim|required|valid_email'
                    )
                );

                $this->form_validation->set_rules($validationRules);

                if ($this->form_validation->run() == FALSE) {
                    //nich geklappt
                } else {
                    //hat geklappt
                }
            } else {
                //html ausgabe mit ausgefüllten feldern
            }
        } else {
            redirect('user');
        }
    }
}